package com.xywy.me;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.constants.ConstantValue;
import com.xywy.common.widget.TitleBar2;
import com.xywy.me.bean.Jtcy;

/**
 * 我 - 个人资料 -修改 名字/姓别/身高/生日
 * @author xiaogd
 *
 */
public class JtcyAddUpdateActivity extends BaseActivity  {
    private static final String  TAG = "JtcyAddUpdateActivity";
    private RelativeLayout rlBack;
    private TextView tvTitle;

    private  RelativeLayout  male,female;
    private  RelativeLayout  height;

    private EditText  etHeight;

    private  Context  mContext;
    private  ImageView maleCheck,feMaleCheck;

    private  int  item=0;
    private  String  sexVal="";
    @Override
    protected void onCreate(Bundle savedInstanceState)  
    {
    	super.onCreate(savedInstanceState);    
        //设置为全屏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.me_jtcy_add_update);

        this.preInit();
        this.initView();
        this.loadData();
        this.setListener();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();

    }
    Jtcy jtcy=null;
    @Override
    public void preInit() {
        mContext = this.context;
        Intent intent =  this.getIntent();
        item = intent.getIntExtra("item",0);
        jtcy = (Jtcy)intent.getSerializableExtra("jtcy");
    }

    @Override
    public void initView() {
        //title
        TitleBar2 titleBar = (TitleBar2)findViewById(R.id.me_jtyc_update_title_bar);
            rlBack =titleBar.getRlBack();
            tvTitle= titleBar.getTitle();
            TextView tvBack= titleBar.getTvBack();
             titleBar.getGo().setVisibility(View.INVISIBLE);
            tvBack.setText(getString(R.string.me_infor_title));


        //姓别 (male + famale)
        male = (RelativeLayout) this.findViewById(R.id.rl_me_jtcy_update_male);
        female = (RelativeLayout) this.findViewById(R.id.rl_me_jtcy_update_female);

        maleCheck = (ImageView) this.findViewById(R.id.iv_me_jtcy_update_male);
        feMaleCheck = (ImageView) this.findViewById(R.id.iv_me_jtcy_update_female);

        height = (RelativeLayout) this.findViewById(R.id.rl_me_jtcy_update_height);
        etHeight = (EditText) findViewById(R.id.et_me_jtcy_update_height);
    }
    int  sexStr =1;
    @Override
    public void loadData() {
        //预加载数据
      //  MLog.i(TAG,"成员参数是=update========："+jtcy.toString());
        clearItem();  //隐藏item
        switch (item){
            case   ConstantValue.SEX:
                tvTitle.setText(getString(R.string.me_infor_sex));
                male.setVisibility(View.VISIBLE);
                female.setVisibility(View.VISIBLE);

                maleCheck.setVisibility(View.VISIBLE);
                feMaleCheck.setVisibility(View.INVISIBLE);
                break;
            case   ConstantValue.HEIGHT:
                tvTitle.setText(getString(R.string.me_infor_height));
                height.setVisibility(View.VISIBLE);
                break;
        }
    }


    /**
     * 点击事件
     * @param view
     */

    public  void onClickUpdate(View view){
         switch (view.getId()){
             case R.id.rl_me_jtcy_update_male:
                  maleCheck.setVisibility(View.VISIBLE);
                  feMaleCheck.setVisibility(View.INVISIBLE);
                  sexStr =1;
                  break;
             case R.id.rl_me_jtcy_update_female:
                 maleCheck.setVisibility(View.INVISIBLE);
                 feMaleCheck.setVisibility(View.VISIBLE);
                 sexStr =2;
                 break;
             case R.id.iv_me_jtcy_height_cancel:
                 etHeight.setText("");
                 break;
         }
    }

    /**
     * 隐藏item
     *
     */
    private void  clearItem(){
        male.setVisibility(View.GONE);
        female.setVisibility(View.GONE);
        height.setVisibility(View.GONE);
    }

    /**
     * 点击保存获取值
     */
    private  void setListener(){
        rlBack.setOnClickListener(onBackListener);
    }
    View.OnClickListener onBackListener =new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //返回
            back();
        }
    };


    @Override
    public void onBackPressed() {
        back();
        super.onBackPressed();
    }

    /**
     * 返回处理
     */
    public void  back(){
           Intent intent =new Intent(this,JtcyActivity.class);
            jtcy.setHeight(etHeight.getText().toString());
            jtcy.setSex(sexVal);
           intent.putExtra("jtcy",jtcy);
           startActivity(intent);
           this.finish();
    }
}



